package com.intexh.quickandroid.module.chat.ChatManager;


import com.intexh.quickandroid.module.chat.ChatHelper;
import com.intexh.quickandroid.module.chat.bean.ChatMessage;

import java.util.UUID;

/**
 * Created by engine on 14-1-2.
 */
public class MessageFactory {
    public static MessageFactory instance;

    public static MessageFactory getInstance() {
        if (instance == null) {
            instance = new MessageFactory();
        }
        return instance;
    }



    /**将文本转换为ChatMessage对象,在此方法设置类型*/
    public ChatMessage createGoodsMessage(String content) {
        ChatMessage chatMessage = getBaseMessage();
        chatMessage.setContent(content);
        chatMessage.setType(ChatMessage.TYPE_BLEND);
        return chatMessage;
    }
    /**将文本转换为ChatMessage对象,在此方法设置类型*/
    public ChatMessage createTextMessage(String content) {
        ChatMessage chatMessage = getBaseMessage();
        chatMessage.setContent(content);
        chatMessage.setType(ChatMessage.TYPE_TEXT);
        return chatMessage;
    }

    public ChatMessage createImageMessage(String url) {
        ChatMessage chatMessage = getBaseMessage();
        chatMessage.setType(ChatMessage.TYPE_IMAGE);
        chatMessage.setLocalUrl(url);//do not set message, message should be serverUrl which is got after upload
        return chatMessage;
    }

    public ChatMessage createVoiceMessage(String url, int length) {
        ChatMessage chatMessage = getBaseMessage();
        chatMessage.setVoiceLength(length);
        chatMessage.setType(ChatMessage.TYPE_VOICE);
        chatMessage.setLocalUrl(url);//do not set message, message should be serverUrl which is got after upload
        return chatMessage;
    }

    public ChatMessage getBaseMessage() {
        ChatMessage chatMessage = new ChatMessage();
        chatMessage.setPlayed(1);
        chatMessage.setId(UUID.randomUUID().toString());
        chatMessage.setCreate_time(System.currentTimeMillis());
        chatMessage.setUid(ChatHelper.getInstance().getUserInfo().getUid());
        chatMessage.setAvatar(ChatHelper.getInstance().getUserInfo().getAvatar());
        chatMessage.setDisplay_name(ChatHelper.getInstance().getUserInfo().getDisplay_name());
        return chatMessage;
    }

}
